package com.leetcode.Offer;

public class JZ63_2 {
    public static int maxProfit(int[] prices) {
        if (prices == null || prices.length == 0) {
            return 0;
        }
        int max = 0, min = prices[0];
        for (int price : prices) {
            if (price > min) {
                max = Math.max(max, price - min);
            } else {
                min = price;
            }
        }
        return max;
    }

    public static void main(String[] args) {
        System.out.println(maxProfit(new int[]{7, 6, 4, 3, 1}));
    }
}
